package com.teacher.mobile.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teacher.common.CommonResult;
import com.teacher.logs.BaseEntity;
import com.teacher.logs.OptionLog;
import com.teacher.logs.mapper.OptionLogMapper;
import com.teacher.pojo.dto.optionLog.OptionLogGetDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zfm
 * @Date: 2022/3/26 19:57
 */
@RestController
@RequestMapping("/pc/option-log")
public class OptionController {

    @Autowired
    private OptionLogMapper optionLogMapper;

    /**
     * 查询日志
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("查询日志")
    public CommonResult<IPage<OptionLog>> getPage(OptionLogGetDto dto) {
        Page<OptionLog> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
        return CommonResult.success(optionLogMapper.selectPage(page, new QueryWrapper<OptionLog>().lambda()
                .eq(StrUtil.isNotBlank(dto.getTitle()), OptionLog::getTitle, dto.getTitle())
                .like(StrUtil.isNotBlank(dto.getUsername()), OptionLog::getUsername, dto.getUsername())
                .orderByDesc(BaseEntity::getCreateTime)));
    }

}
